var fs=require('fs');

openAndWrite(new Buffer('0123456789'), function (err) {
    if(err){
        console.log('Error 1:',err);
        return;
    }

    console.log('Done.');
});

function openAndWrite(buffer,cb){
    fs.open('write.txt','w', function (err, fd) {
        if(err)return cb(err);

        var offset=10,length=buffer.length,pos=null;
        fs.write(fd,buffer,5,3,pos, function (err, written) {
            console.log('written:',written);
            fs.close(fd, function () {
                cb(err);
            });
        });
    });
}